// pages/test/test.js
const HTTP = require('../../models/HTTP')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    musics:[]           
  },
  time: function (x) {
    if (x / 1000 / 60 < 10) {
      var min = ('0' + Math.floor(x / 1000 / 60))
    } else {
      min = Math.floor(x / 1000 / 60)
    }

    if (x / 1000 % 60 < 10) {
      var sec = '0' + Math.round(x / 1000 % 60)
    } else {
      sec = Math.round(x / 1000 % 60)
    }
    return min + ':' + sec;
  },
  onShow: async function (options) {
    var data = await HTTP.getSearch("你")
    console.log(data.data.result)
    var songs = res.data.result.songs;
    var musics = [];
    for(let i=0;i<songs.length;i++){
      var obj = {};
      obj.name =songs[i].name;
      obj.id = songs[i].id;
      var data = await HTTP.getDetail(songs[i].id);
      obj.picUrl = data.data.songs[0].al.picUrl
      obj.artistName = songs[i].artists[0].name;
      obj.time = this.time(songs[i].duration);
      obj.musicUrl = `https://music.163.com/song/media/outer/url?id=${songs[i].id}`;
      musics.push(obj)
    }
    console.log(musics.length)
    this.setData({
      musics
    })
  
}
})